<?php

namespace app\admin\model\shortvideo;

use think\Model;


class Script extends Model
{

    

    

    // 表名
    protected $name = 'shortvideo_script';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'video_type_text',
        'image_type_text',
        'is_banner_text',
        'status_text',
        'is_allow_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4')];
    }

    public function getVideoTypeList()
    {
        return ['1' => __('Video_type 1'), '2' => __('Video_type 2')];
    }

    public function getImageTypeList()
    {
        return ['1' => __('Image_type 1'), '2' => __('Image_type 2')];
    }

    public function getIsBannerList()
    {
        return ['1' => __('Is_banner 1'), '2' => __('Is_banner 2')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2')];
    }

    public function getIsAllowList()
    {
        return ['1' => __('Is_allow 1'), '2' => __('Is_allow 2')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getVideoTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['video_type']) ? $data['video_type'] : '');
        $list = $this->getVideoTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getImageTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['image_type']) ? $data['image_type'] : '');
        $list = $this->getImageTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsBannerTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_banner']) ? $data['is_banner'] : '');
        $list = $this->getIsBannerList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsAllowTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_allow']) ? $data['is_allow'] : '');
        $list = $this->getIsAllowList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
